|
|
|
|
|
|
|
Recording User Activity in an Audit File |
|
|
|
|
|
|
|
|
The next step is to add code to the current project that records each time a user logs in or out of the application. You need to modify the general declarations section to add a module-level object variable for the logging object: |
|
|
|
|
|
|
|
|
Option Explicit
'
' project-level vars
'
Public objUser As Object
Public objLog As Object ' <<< new line |
|
|
|
|
|
|
|
|
You also need to modify the Main routine to include the initialization of the log object and writes to the log file. Listing 21.40 shows how your Main routine should look now. |
|
|
|
|
|
|
|
|
Listing 21.40. Adding audit logging to the Main routine in the test project. |
|
|
|
|
|
|
|
|
Public Sub Main()
'
' main entry for form-less project
'
Set objUser = New usrObject
objUser.DBName = App.Path & "\..\..\data\security\security.mdb"
'
Set objLog = New logObject
objLog.filename = App.Path & "\" & App.EXEName & ".log"
objLog.LogHeader = App.EXEName & " Audit Log"
'
' now try to start up
If objUser.UserLogin = True Then
objLog.WriteLog "UserLogin", "Main"
If objUser.CheckRights("UserMaint", urReadModAdd) Then
objLog.WriteLog "UserMaint", "Main", "StartForm"
objUser.UsersForm
objLog.WriteLog "UserMaint", "Main", "ExitForm"
Else
MsgBox "You do not have rights to this application", vbExclamation,
"Login Failed"
End If
objUser.LogUser urLogOut
objLog.WriteLog "UserLogOut", "Main"
End If
'
End
'
End Sub |
|
|
|
|
|
|
|
|
Now save and run the test project. Log into the application with default as the User ID and Password and then log back out. You have just created an audit file called PRJUSRTEST.LOG in |
|
|
|
|
|